// pages/orderinfo/orderinfo.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderid:0,
    order:{},
    post:{},
    lasttime:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({ orderid: parseInt(options.orderid) });
    that.Find_POrderByID();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  copy1: function(e){
    var num = e.currentTarget.dataset.num;
    wx.setClipboardData({
      data: num,
      success: function (res) {
        app.showSuccess("复制成功");
      }
    })
  },
  copy2: function (e) {
    var expressnum = e.currentTarget.dataset.expressnum;
    wx.setClipboardData({
      data: expressnum,
      success: function (res) {
        app.showSuccess("复制成功");
      }
    })
  },
  openTui: function(e){
    var orderid = this.data.orderid;
    var orderdetailid = e.currentTarget.dataset.orderdetailid;
    var productid = e.currentTarget.dataset.productid;
    var money = e.currentTarget.dataset.money;
    var mobile = e.currentTarget.dataset.mobile;
    wx.navigateTo({
      url: '/pages/tui/tui?orderid=' + orderid + "&orderdetailid=" + orderdetailid + "&productid=" + productid + "&money=" + money + "&mobile=" + mobile
    })
  },
  Find_POrderByID: function () {
    var that = this;
    var data = {};
    data.act = "Find_POrderByID";
    data.orderid = this.data.orderid;
    wx.showLoading({
      title: '数据加载中...',
    })
    app.Ajax(data, function (json) {
      wx.hideLoading();
      var lasttime = "";
      var post = {};
      if (json.data.Post!=""){
        post = JSON.parse(json.data.Post);
        if (post.Success && post.Traces.length > 0){
          lasttime = post.Traces.reverse()[0].AcceptTime;
        }else{
          lasttime="未知"
        }
      }
      that.setData({ order: json.data, post: post, lasttime: lasttime});
      wx.stopPullDownRefresh();
    });
  },
  openPost:function(e){
    wx.navigateTo({
      url: '/pages/post/post?from=orderinfo&logistics=' + this.data.order.Logistics + "&poststate=" + this.data.order.PostState + "&expressnum=" + this.data.order.ExpressNum + "&post="+JSON.stringify(this.data.post) + "&img="+this.data.order.ChildList[0].Img
    })
  }
})